from lab_2_conf_manage_neo4j import get_neo4j_graph
from langchain_community.vectorstores.neo4j_vector import remove_lucene_chars


# 该函数用于创建一个名为 entity 的全文索引
def create_graph_full_txt_index_qry():
    graph = get_neo4j_graph() 
    graph.query("CREATE FULLTEXT INDEX entity IF NOT EXISTS FOR (e:__Entity__) ON EACH [e.id]")
    print("Create Graph Full Text Index query")


# 结果 "Where~2 AND was~2 AND Amelia~2 AND Earhart~2 AND born~2"
def gen_full_txt_qry(query: str) -> str:
    full_txt_qry = ""
    words = [el for el in remove_lucene_chars(query).split() if el]
    for word in words[:-1]:
        full_txt_qry += f" {word}~2 AND"
    full_txt_qry += f" {words[-1]}~2"
    return full_txt_qry.strip()


if __name__ == "__main__":
    qry = "Where was Amelia Earhart born?"
    result = gen_full_txt_qry(qry)
    create_graph_full_txt_index_qry()
    print(result)
